package com.information.manage.basic.audit.controller;

import com.information.manage.basic.audit.service.AuditModelService;
import com.information.manage.basic.common.result.Result;
import com.information.manage.basic.audit.model.query.AddAuditModelQuery;
import com.information.manage.basic.audit.model.query.AuditModelQuery;
import com.information.manage.basic.audit.model.query.UpdateAuditModelQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


@Api(tags = "审核模板")
@RestController
@RequestMapping("/audit/model")
public class AuditModelController {

    @Autowired
    private AuditModelService auditModelService;

    @PostMapping(value = "/add")
    @ApiOperation(value = "添加模板", notes = "添加模板")
    public Result createAuditTemplate(HttpServletRequest request, @RequestBody @Valid AddAuditModelQuery addAuditModelQuery){
        return auditModelService.createAuditTemplate(addAuditModelQuery, request);
    }


    @GetMapping(value="/getAuditTemplatesPage")
    @ApiOperation(value = "分页查询模板", notes = "分页查询模板")
    public Result getAuditTemplatesPage(AuditModelQuery auditModelQuery) {
        return auditModelService.getAuditTemplatesPage(auditModelQuery);
    }


    @GetMapping(value="/getAuditTemplateById/{id}")
    @ApiOperation(value = "id获取模板", notes = "id获取模板")
    public Result getAuditTemplateById (@PathVariable("id") Long id) {
        return auditModelService.getAuditTemplateById(id);
    }


    @PutMapping(value="/update")
    @ApiOperation(value = "更新模板", notes = "更新模板")
    public Result updateAuditTemplate(HttpServletRequest request, @RequestBody @Valid UpdateAuditModelQuery updateAuditModelQuery) {
        return auditModelService.updateAuditTemplate(request, updateAuditModelQuery);
    }


    @PostMapping(value="/apply")
    @ApiOperation(value = "应用模板", notes = "应用模板")
    public Result applyAuditTemplate(HttpServletRequest request, @RequestParam("id") Long id) {
        Result resultDTO = auditModelService.applyAuditTemplate(id, request);
        return Result.ok(resultDTO.getData());
    }


    @PostMapping(value="/stop")
    @ApiOperation(value = "停用模板", notes = "停用模板")
    public Result stopAuditTemplate(HttpServletRequest request, @RequestParam("id") Long id) {
        Result resultDTO = auditModelService.stopAuditTemplate(id, request);
        return Result.ok(resultDTO.getData());
    }


    @DeleteMapping(value="/delete/{id}")
    @ApiOperation(value = "删除模板", notes = "删除模板")
    public Result deleteAuditTemplate(@PathVariable("id") Long id){
        Result resultDTO = auditModelService.deleteAuditTemplate(id);
        return Result.ok(resultDTO.getData());
    }

}
